<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../taglibs.jsp" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${path}/static/lib/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" href="${path}/static/lib/layui/css/layui.css" media="all">
</head>
<body>
	
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
	  <legend>编辑信息</legend>
	</fieldset>
	
	<form class="layui-form layui-form-pane" id="ajax_form" method="post" onsubmit="return false">
	
	<div class="layui-form-item">
	    <label class="layui-form-label">ID</label>
	    <div class="layui-input-block">
	      <input type="text" name="id" placeholder="ID" class="layui-input" value="${product.id}">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">商品名称</label>
	    <div class="layui-input-block">
	      <input type="text" name="name" placeholder="名称" class="layui-input" value="${product.name}">
	    </div>
	  </div>
	  
<!-- 	  <div class="layui-form-item"> -->
<!-- 	    <label class="layui-form-label">商品分类</label> -->
<!-- 	    <div class="layui-input-inline"> -->
<%-- 	      <input type="text" name="categoryId" lay-verify="required" placeholder="分类" class="layui-input" value="${product.categoryId}"> --%>
<!-- 	    </div> -->
<!-- 	  </div> -->
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">子标题</label>
	    <div class="layui-input-inline">
	      <input type="text" name="subtitle" lay-verify="required" placeholder="子标题" class="layui-input" value="${product.subtitle}">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">主图片</label>
	    <div class="layui-input-inline">
	      <input type="text" name="mainImage" lay-verify="required" placeholder="主图片" class="layui-input" value="${product.mainImage}">
	    </div>
	  </div>
	  
<!-- 	  <div class="layui-form-item"> -->
<!-- 	    <label class="layui-form-label">子图片</label> -->
<!-- 	    <div class="layui-input-inline"> -->
<%-- 	      <input type="text" name="subImages" lay-verify="required" placeholder="子图片" autocomplete="off" class="layui-input" value="${product.subImages}"> --%>
<!-- 	    </div> -->
<!-- 	  </div> -->
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">商品详情</label>
	    <div class="layui-input-inline">
	      <input type="text" name="detail" lay-verify="required" placeholder="细节" class="layui-input" value="${product.detail}">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">商品价格</label>
	    <div class="layui-input-inline">
	      <input type="text" name="price" lay-verify="required" placeholder="价格" class="layui-input" value="${product.price}">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">商品库存</label>
	    <div class="layui-input-inline">
	      <input type="text" name="stock" lay-verify="required" placeholder="库存" class="layui-input" value="${product.stock}">
	    </div>
	  </div>
	  
	  <div class="layui-form-item" pane="">
	    <label class="layui-form-label">状态</label>
	    <c:if test="${product.status == 1}">
		    <div class="layui-input-block">
		      <input type="radio" name="status" value="1" title="在售" checked="">
		      <input type="radio" name="status" value="2" title="下架">
		      <input type="radio" name="status" value="3" title="删除">
		    </div>
	    </c:if>
	    <c:if test="${product.status == 2}">
		    <div class="layui-input-block">
		      <input type="radio" name="status" value="1" title="在售">
		      <input type="radio" name="status" value="2" title="下架" checked="">
		      <input type="radio" name="status" value="3" title="删除">
		    </div>
	    </c:if>
	    <c:if test="${product.status == 3}">
		    <div class="layui-input-block">
		      <input type="radio" name="status" value="1" title="在售">
		      <input type="radio" name="status" value="2" title="下架">
		      <input type="radio" name="status" value="3" title="删除" checked="">
		    </div>
	    </c:if>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">创建时间</label>
	    <div class="layui-input-inline">
	      <input type="text" name="createTime"  class="layui-input" id="createTimeId" placeholder="yyyy-MM-dd" value="${product.createTime}">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">修改时间</label>
	    <div class="layui-input-inline">
	      <input type="text" name="updateTime"  class="layui-input" id="updateTimeId" placeholder="yyyy-MM-dd" value="${product.updateTime}"> 
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <button class="layui-btn" onclick="submitForm()" value="编辑">编辑</button>
	  </div>
	</form>

	<script src="${path}/static/lib/jquery-1.11.3.js"></script>
	<script src="${path}/static/lib/mylayer.js"></script>
	<script src="${path}/static/lib/util.js"></script>
	<script src="${path}/static/lib/layui/layui.js"></script>
	<script>
	layui.use(['form', 'laydate'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,laydate = layui.laydate;
	  
	  laydate.render({
		  elem: '#createTimeId'
		  ,trigger: 'click'
	  });
	  
	  laydate.render({
		  elem: '#updateTimeId'
		  ,trigger: 'click'
	  });
	  
	});
	
	function submitForm() {
		
		$.ajax({
			url : "${path}/product/update.action",
			type : "post",
			dataType : "json",
			data : $("#ajax_form").serialize(),
			success : function(jsonObj) {
				console.log(jsonObj);
				if(jsonObj.code == util.SUCCESS) {
					mylayer.successMsg(jsonObj.msg);
					//当你在iframe页面关闭自身时
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					setTimeout(function(){
						parent.layer.close(index); //再执行关闭 
						// 刷新父页面
						window.parent.location.reload();
					},1000);
				} else {
					mylayer.errorMsg(jsonObj.msg);
				}
				
			}
		});
	}
</script>

</body>
</html>